home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6908 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: grouper.Exis.Net!usenet
  2. From: Chandler Pitcher <pitch@exis.net>
  3. Newsgroups: comp.lang.c++
  4. Subject: Problem with Linked Lists
  5. Date: Tue, 20 Feb 1996 17:10:31 -0500
  6. Organization: OAKLAND  RAIDERS
  7. Message-ID: <312A46D7.608A@exis.net>
  8. NNTP-Posting-Host: 45.exis.net
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0 (Win95; I)
  13.  
  14. Help!! I'm trying to create a "circular" list that wraps around again from end to 
  15. beginning, but I am having no luck at setting up a head pointer. The function simply reads names 
  16. from a file and puts them in the list, I am using the word "Stop" as a sentinel. Once the 
  17. function is finished, I try to assign the link to the head, but head is following along with 
  18. the current pointer. How do I keep head and current pointing to the same thing in the 
  19. beginning, but then separate thru the rest of the function. struct node*, and node* head are 
  20. assigned in the main.
  21.  
  22.  
  23. void read_list(node*& head)
  24. {
  25.     head = new node;
  26.     node *current = head;
  27.     current = head;
  28.     stringtype temp;
  29.     infile>>temp;
  30.     while (strcmp("Stop", temp))
  31.     {
  32.         strcpy(current->name, temp);
  33.         outfile<<current->name<<" is added to the list."<<endl;
  34.         infile>>temp;
  35.         if (!strcmp("Stop", temp))
  36.             current->link = new node;
  37.     };
  38.     current->link = head;
  39.     return;
  40. };
  41.  
  42.  
  43.     Thanks for any help!! I'm really lost at this point!!!
  44.  
  45. Chandler Pitcher          |           
  46. Virginia Beach, Virginia  |   O A K L A N D   R A I D E R S
  47.     <pitch@exis.net>      |
  48.